#ifndef LGE_SEMAPHORE_H
#define LGE_SEMAPHORE_H

class Semaphore : public Uncopyable
{
	HANDLE mSemaphoreHandle;
public:
	Semaphore(SizeT maxCount, SizeT initialValue=0)
	{
		mSemaphoreHandle = CreateSemaphore(NULL, (LONG)initialValue, 
			(LONG)maxCount, NULL);
	}

	inline void decrement()
	{
		WaitForSingleObject(mSemaphoreHandle, INFINITE);
	}

	inline bool increment()
	{
		return (ReleaseSemaphore(mSemaphoreHandle, 1, NULL) != 0);
	}

	~Semaphore()
	{
		CloseHandle(mSemaphoreHandle);
	}
};

#endif
